<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.JSONArray, org.json.JSONException, org.json.JSONObject, br.com.seuimovelnamao.model.Imovel, java.util.List" %>
<%
try {
    JSONArray array = new JSONArray();
    
    JSONObject jsonOne;

    List<Imovel> imoveis = (List<Imovel>)request.getAttribute("imoveis");
    
    for(Imovel imovel : imoveis){
    	jsonOne = new JSONObject();

    	jsonOne.put("id", imovel.getId());
        jsonOne.put("title", imovel.getTitulo());
        jsonOne.put("lat", imovel.getLat());
        jsonOne.put("lng", imovel.getLng());
        jsonOne.put("tipo", imovel.getCategoria());
        jsonOne.put("endereco", imovel.getEndereco().getNomeCompleto());
        jsonOne.put("dormitorios", imovel.getDormitorios());
        jsonOne.put("banheiros", imovel.getBanheiros());
        jsonOne.put("telefone", imovel.getUsuario().getTelefone());
        jsonOne.put("celular", imovel.getUsuario().getCelular());
        jsonOne.put("email", imovel.getUsuario().getEmail());
        jsonOne.put("categoria", imovel.getCategoria());
        jsonOne.put("intencao", imovel.getIntencao());
        
        array.put(jsonOne);
    }
    
    out.println(array);
                    
} catch (JSONException e) {
    e.printStackTrace();
}
%>